<?php 
     get_header();
?>
<div class="row-fluid browses">
        <div class="row-fluid header-coupon">
            <h1>Browse Categories</h1>
        </div>
        <?php 
            global $wpdb;
            $my_query = "
                SELECT term_id as cat_id FROM {$wpdb->term_taxonomy} WHERE taxonomy='store_category' AND parent = 0
            ";
            $categories = $wpdb->get_results($my_query);
            foreach($categories as $categorys){
                $parent_id = $categorys->cat_id;
                $parent_term = get_term_by('id',$parent_id,'store_category');
                $parent_name = $parent_term->name;
                $parent_link = get_term_link($parent_term->slug, 'store_category');
                $my_sql ="SELECT term_id from {$wpdb->term_taxonomy} WHERE parent=$parent_id";
                $term_children = $wpdb->get_results($my_sql);
                ?>
                <div class="row-fluid">
                    <p class="parent_term">
                        <a class="accessories" href="<?php echo $parent_link;?>" title="<?php echo $parent_name;?>"><?php echo $parent_name;?></a>
                    </p>
                    <?php 
                       foreach ($term_children as $k=>$child){
                           $child_term = get_term_by( 'id', $child->term_id, 'store_category' );
                           $child_name = $child_term->name;
                       ?>
                          <ul class="categories">
                            <li><a class="accessories" href="<?php echo get_term_link( $child_name, 'store_category');?>" title="<?php echo $child_name;?>"><?php echo $child_name;?></a></li>
                          </ul>              
                      <?php }
                    ?>
                </div>
                <hr/>
            <?php }
        ?>
</div>
<div class="row-fluid top-store-category">
     <?php if(is_active_sidebar('cs-text-link-sidebar')) dynamic_sidebar( 'cs-text-link-sidebar' ); ?>
</div>
<?php  get_footer(); ?>